package cn.pro.CCY.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class AppJdbcSelect {

    public static void main(String[] args) throws Exception {

        //必须掌握
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:13306/test?useSSL=false";
        String user = "root";
        String password = "root";
        Connection connection = DriverManager.getConnection(url, user, password);

        //3.创建陈述句对象
        Statement statement = connection.createStatement();

        //4.执行查询
        String sql = "SELECT id, `username` FROM `user`";
        ResultSet set = statement.executeQuery(sql);

        //5.获取数据
        set.next();
        String string = set.getString(2);
        System.out.println(string);

        /* //自主练习
        String string2 = set.getString(1);
        System.out.println(string2);

        set.next();
        String string1 = set.getString(2);
        System.out.println(string1);

        String string3 = set.getString(1);
        System.out.println(string3); */



    }
}
